package com.tanhua.manage.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.server.api.QuanZiApi;
import com.tanhua.dubbo.server.pojo.Comments;
import com.tanhua.manage.mapper.UserInfoMapper;
import com.tanhua.manage.pojo.UserInfo;
import com.tanhua.manage.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentPageService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Reference(version = "1.0.0")
    private QuanZiApi quanZiApi;

    public PageResult queryCommentList(String page, String pageSize, String sortProp, String sortOrder, String messageId) {
        List<Comments> list = this.quanZiApi.queryCommentList(page,pageSize,sortProp,sortOrder,messageId);
        //注入
        for (Comments comments : list) {
            QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("user_id",comments.getUserId());
            comments.setNickname(this.userInfoMapper.selectOne(queryWrapper).getNickName());
        }
        PageResult pageResult = new PageResult();
        pageResult.setPages(2);
        pageResult.setPage(Integer.valueOf(page));
        pageResult.setPagesize(Integer.valueOf(pageSize));
        pageResult.setCounts(40);
        pageResult.setItems(list);
        return pageResult;
    }
}
